package com.yiyahui.project.erp.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yiyahui.framework.aspectj.lang.annotation.Log;
import com.yiyahui.framework.aspectj.lang.enums.BusinessType;
import com.yiyahui.project.erp.domain.YiyaChannel;
import com.yiyahui.project.erp.service.IYiyaChannelService;
import com.yiyahui.framework.web.controller.BaseController;
import com.yiyahui.framework.web.domain.AjaxResult;
import com.yiyahui.common.utils.poi.ExcelUtil;
import com.yiyahui.framework.web.page.TableDataInfo;

/**
 * 渠道Controller
 * 
 * @author yiyahui
 * @date 2020-05-03
 */
@RestController
@RequestMapping("/erp/channel")
public class YiyaChannelController extends BaseController
{
    @Autowired
    private IYiyaChannelService yiyaChannelService;

    /**
     * 查询渠道列表
     */
    @PreAuthorize("@ss.hasPermi('erp:channel:list')")
    @GetMapping("/list")
    public TableDataInfo list(YiyaChannel yiyaChannel)
    {
        startPage();
        List<YiyaChannel> list = yiyaChannelService.selectYiyaChannelList(yiyaChannel);
        return getDataTable(list);
    }

    /**
     * 导出渠道列表
     */
    @PreAuthorize("@ss.hasPermi('erp:channel:export')")
    @Log(title = "渠道", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(YiyaChannel yiyaChannel)
    {
        List<YiyaChannel> list = yiyaChannelService.selectYiyaChannelList(yiyaChannel);
        ExcelUtil<YiyaChannel> util = new ExcelUtil<YiyaChannel>(YiyaChannel.class);
        return util.exportExcel(list, "channel");
    }

    /**
     * 获取渠道详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:channel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yiyaChannelService.selectYiyaChannelById(id));
    }

    /**
     * 新增渠道
     */
    @PreAuthorize("@ss.hasPermi('erp:channel:add')")
    @Log(title = "渠道", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YiyaChannel yiyaChannel)
    {
        return toAjax(yiyaChannelService.insertYiyaChannel(yiyaChannel));
    }

    /**
     * 修改渠道
     */
    @PreAuthorize("@ss.hasPermi('erp:channel:edit')")
    @Log(title = "渠道", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YiyaChannel yiyaChannel)
    {
        return toAjax(yiyaChannelService.updateYiyaChannel(yiyaChannel));
    }

    /**
     * 删除渠道
     */
    @PreAuthorize("@ss.hasPermi('erp:channel:remove')")
    @Log(title = "渠道", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yiyaChannelService.deleteYiyaChannelByIds(ids));
    }
}
